//
//  BLCommentViewController.m
//  blanket
//
//  Created by Mac on 2017/12/5.
//  Copyright © 2017年 stoneobs@icloud.com. All rights reserved.
//

#import "BLCommentViewController.h"
#import "STXingXIngView.h"
#import "STTextView.h"
@interface BLCommentViewController ()
@property(nonatomic, strong) STXingXIngView                     *qulityView;
@property(nonatomic, strong) STXingXIngView                     *speediew;
@property(nonatomic, strong) STXingXIngView                     *attitudeView;
@property(nonatomic, strong) STTextView                     *textView;
@end

@implementation BLCommentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"服务评价";
    self.tableView.backgroundColor = [UIColor whiteColor];
    [self configSubView];
    [self st_setRightItemWithTitle:@"提交" titleColor:BL_BlueBackGroundColor];
    // Do any additional setup after loading the view.
}
#pragma mark --subView
- (void)configSubView{
    UIView * header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 122)];
    header.backgroundColor = self.tableView.backgroundColor;
    
    STLabel * desLable = [[STLabel alloc] initWithFrame:CGRectMake(10, 0, UIScreenWidth -20, 20)
                                                   text:@"提示:每个月只能对服务进行评价一次哟"
                                              textColor:BL_secendTextColor
                                                   font:13
                                            isSizetoFit:NO
                                          textAlignment:NSTextAlignmentCenter];
    [header addSubview:desLable];
    
    STLabel * qulityLable = [[STLabel alloc] initWithFrame:CGRectMake(20, desLable.bottom  +20, 70, 40)
                                                     text:@"洗涤质量"
                                                textColor:BL_firstTextColor
                                                     font:15
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    [header addSubview:qulityLable];
    self.qulityView = [[STXingXIngView alloc] initWithFrame:CGRectMake(qulityLable.right + 10, 0, 150, 40) maxsNum:5];
    self.qulityView.centerY = qulityLable.centerY;
    self.qulityView.chosedNum = 0;
    [header addSubview:self.qulityView];
    
    STLabel * speedLable = [[STLabel alloc] initWithFrame:CGRectMake(20, qulityLable.bottom + 20, 70, 40)
                                                      text:@"洗涤速度"
                                                 textColor:BL_firstTextColor
                                                      font:15
                                               isSizetoFit:NO
                                             textAlignment:NSTextAlignmentLeft];
    [header addSubview:speedLable];
    self.speediew = [[STXingXIngView alloc] initWithFrame:CGRectMake(qulityLable.right + 10, 0, 150, 40) maxsNum:5];
    self.speediew.centerY = speedLable.centerY;
    self.speediew.chosedNum = 0;
    [header addSubview:self.speediew];
    
    STLabel * attLable = [[STLabel alloc] initWithFrame:CGRectMake(20, speedLable.bottom + 20, 70, 40)
                                                     text:@"洗涤态度"
                                                textColor:BL_firstTextColor
                                                     font:15
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    [header addSubview:attLable];
    self.attitudeView = [[STXingXIngView alloc] initWithFrame:CGRectMake(qulityLable.right + 10, 0, 150, 40) maxsNum:5];
    self.attitudeView.centerY = attLable.centerY;
    self.attitudeView.chosedNum = 0;
    [header addSubview:self.attitudeView];
    
    self.textView = [[STTextView alloc] initWithFrame:CGRectMake(15, self.attitudeView.bottom + 20, UIScreenWidth - 30, 200)];
    self.textView.placeholder = @"请输入留言";
    self.textView.backgroundColor = FlatWhite;
    [header addSubview:self.textView];

    
    header.height = _textView.bottom + 20;
    self.tableView.tableHeaderView = header;
    
}

- (void)st_rightBarAction:(id)sender{
    if (self.qulityView.chosedNum == 0) {
        [SVProgressHUD showErrorWithStatus:@"你还未选择洗涤质量评价"];
        return;
    }
    if (self.speediew.chosedNum == 0) {
        [SVProgressHUD showErrorWithStatus:@"你还未选择洗涤速度评价"];
        return;
    }
    if (self.attitudeView.chosedNum == 0) {
        [SVProgressHUD showErrorWithStatus:@"你还未选择洗涤态度评价"];
        return;
    }
    if (!self.textView.text.length) {
        [SVProgressHUD showErrorWithStatus:@"你还未留言"];
        return;
    }
    [self sendCommentRequest];
}
- (void)sendCommentRequest{
    [SVProgressHUD showWithStatus:@"请稍后"];
    NSMutableDictionary * dic = [NSMutableDictionary new];
    [dic setObject:debugToken forKey:@"token"];
    NSString * url = [NSString stringWithFormat:@"%@%@",releaseServerUrlHeader,@"index.php/Api/Basics/serviceAction"];
    if ([STUserManger defult].userID.length) {
        [dic setObject:[STUserManger defult].userID forKey:@"uid"];
    }
    [dic setObject:@(self.qulityView.chosedNum) forKey:@"mass"];
    [dic setObject:@(self.speediew.chosedNum) forKey:@"speed"];
    [dic setObject:@(self.attitudeView.chosedNum) forKey:@"manner"];
    if (self.textView.text.length) {
         [dic setObject:self.textView.text forKey:@"content"];
        
    }
    [[STNetWrokManger defaultClient] requestWithPath:url
                                              method:STHttpRequestTypePost
                                          parameters:dic
                                             success:^(NSURLSessionDataTask *operation, id responseObject) {
                                                 [self.tableView.mj_header endRefreshing];
                                                 [SVProgressHUD dismiss];
                                                 [SVProgressHUD showSuccessWithStatus:@"评价成功"];
                                                 [self.navigationController popViewControllerAnimated:YES];
                                                 
                                             } failure:^(NSString *stateCode, STError *error) {
                                                 [self.tableView.mj_header endRefreshing];
                                                 [SVProgressHUD dismiss];
                                                 [SVProgressHUD showErrorWithStatus:error.desc];
                                             }];
}
@end
